package pack0828;

import javax.swing.plaf.basic.BasicTreeUI;
import java.util.*;

public class DemoA {
    public static void a(){
        Set<String> set = new HashSet<>();
        set.add("aa");
        set.add("bb");
        set.add("cc");
        set.add("dd");
        set.add(null);
        set.add("dd");//不能添加进去，set的不可重复性
        System.out.println(set);
        set.remove("bb");
        System.out.println(set);
        int i = set.size();
        System.out.println(i);
        Iterator<String> it = set.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
    }
    //set中 自定义数据类型的曾改
    public static void b1(){
        Emp e1 = new Emp(1,"aa","程序员",1822);
        Emp e2 = new Emp(2,"bb","程序员",4552);
        Emp e3 = new Emp(3,"cc","程序员",4422);
        Emp e4 = new Emp(4,"dd","程序员",5554);
        Emp e5 = new Emp(5,"ee","程序员",5652);
        Set<Emp> set = new HashSet<>();
        set.add(e1);set.add(e2);set.add(e3);set.add(e4);set.add(e5);
        System.out.println(set);
        e2.setEname("ii");
        System.out.println(set);
    }
    //set 中int原始数据类型，一个值为一个地址，给同一个名字赋值时就是给这个名字一个新的地址，需要重新添加
    public static void b2(){
        Set<Integer> set = new HashSet<>();
        int a1 = 45;
        int a2 = 65;
        int a3 = 52;
        set.add(a1);
        set.add(a2);
        set.add(a3);
        System.out.println(set);
        a2 = 34;
        System.out.println(set);
    }
    //set 中String是常量，值不可改变，当给同一个名字一个新值时，相当于重新定义了一个String类型的值，
    // 并且名字相同，新定义的值则是一个新的地址，需要重新添加
    public static void b3(){
        HashSet<String> set = new HashSet<>();
        String s1 = "aa";
        String s2 = "bb";
        String s3 = "cc";
        set.add(s1);
        set.add(s2);
        set.add(s3);
        System.out.println(set);
        s2 = "dd";
        System.out.println(set);
    }
    //需要重新添加
    public static void b4(){
        Emp e1 = new Emp(1,"aa","程序员",1822);
        Emp e2 = new Emp(2,"bb","程序员",4552);
        Emp e3 = new Emp(3,"cc","程序员",4422);
        Emp e4 = new Emp(4,"dd","程序员",5554);
        Emp e5 = new Emp(5,"ee","程序员",5652);
        Set<Emp> set = new HashSet<>();
        set.add(e1);set.add(e2);set.add(e3);set.add(e4);set.add(e5);
        System.out.println(set);
        e5 = new Emp(6,"ff","程序员",4569);
        System.out.println(set);
    }
    //Set 中查找
    public static void c1(){
        Set<Integer> set = new HashSet<>();
        set.add(3);set.add(4);
        boolean b = set.contains(3);
        System.out.println(b);
    }
    //Set 中查找 新地址不添加则找不到
    public static void c2(){
        Emp e1 = new Emp(1,"aa","程序员",1822);
        Emp e2 = new Emp(2,"bb","程序员",4552);
        Set<Emp> set = new HashSet<>();
        set.add(e1);set.add(e2);
        Emp e3 = new Emp(2,"bb","程序员",4552);
        boolean b = set.contains(e3);
        System.out.println(b);
    }
    //Set 排序
    public static void d(){
        Set<Integer> set = new HashSet<>();
        set.add(23);set.add(45);set.add(65);
        System.out.println(set);
        List<Integer> list = new ArrayList<>(set);
        Collections.sort(list);
        System.out.println(list);
    }

    public static void main(String[] args) {
       b1();
    }
}
